package zhupf.test.designPattern.singleton;

/**
 * 单例模式（恶汉）
 * 第二种：静态代码块
 */
public class SingletonTest02 {
    public static void main(String[] args) {
        System.out.println(Singleton02.getInstance()==Singleton02.getInstance());
    }
}

/**
 * 将实现方法交给静态代码块，和静态常量效果一样，优缺点也一样
 */
class Singleton02{

    private static  Singleton02 singleton ;

    static{
        singleton = new Singleton02();
    }

    private Singleton02(){

    }

    public static Singleton02 getInstance(){
        return singleton;
    }
}
